<?php

  namespace Home\Controller;
  use Think\Controller;

  class IndexController extends Controller

  {

         public function index()

   {


    // 实例化model
    $info = M();
    // 查询车系和车辆详情信息,图片信息
   // 

    $xin = $info->
field('t.typename,t.pid,t.hot,i.id,i.ontime,i.age,i.year,i.gas,i.series,i.price,i.nprice,i.comfort,i.standard,i.mile,p.cpic')->where('t.id=i.xid&&i.id=p.cid&&i.status=1')->table('__TYPE__ t,__INFO__ i,__PIC__ p')->order($order)->group('p.cid')->limit(12)->select();

         // dump($xin);exit;
      $type = M('type');
      $model=M('city');
      $pic = M('gzjxt');
      $conf = M('config');

     // 查询网络配置
    $config = $conf->where('status=1')->select();
     // dump($config[0]['status']);exit;

     if($config[0]['status']==null){

    echo '<marquee behavior="" direction="left">

     <center style="color:red;font-size:60px">


    网站正在紧急维护,谢谢您的光临！！！

        </center></marquee>';

        exit;

     }

 

     
          $i=0;
     foreach ($xin as $key => $value) {
     
          // dump($value['cpic']);
          $where['id'] = $value['pid'];
                

          $xin[$i]['pai'] = $type->where($where)->select()[0]['typename'];
            
           $i++;


     }  

     // dump($xin);exit;

   // 热门城市查询
   $remen = $model->where('hot=1&&status=1')->select();
   $city = $model->select();
   // 热门品牌查询
   $re = $type->where('hot=1&&pid=0&&status=1')->select();
    // 热门车系查询
   $res = $type->where('hot=1&&status=1')->select();
   $photo = $pic->where('status=1')->select();

   // dump($pm);exit;
      // 查询数据
     $M['letter']=['BETWEEN','A,M'];
     $Z['letter']=['BETWEEN','N,Z'];
 
    // 查询a-m n-z的数组
    $cm = $type->where($M)->select();
    $cz = $type->where($Z)->select();
   $result = \Org\LAMP\CatTree::getTree($res);

       // dump($result);exit;
         // dump($remen);
         // dump($city);
   // 定义空数组，接收数据

   $arr= [];
   $brr= [];
   $crr= [];
    // 变量拼接城市，排序
   foreach ($city as $key => $value) {
    $arr[$value['letter']][] =$value;

  }
  // 变量拼接汽车品牌，排序
   foreach ($cm as $ke => $value) {
    $brr[$value['letter']][] = $value;

  }
  // 变量拼接汽车品牌，排序
   foreach ($cz as $ke => $value) {
    $crr[$value['letter']][] = $value;

  }
    // 变量赋值
     $city = $arr;
     $data1 = $brr;
     $data2 = $crr;

    // dump($data1); exit;

   // 分配模板
    // 热门城市
   $this->assign('remen',$remen);
   // 从A-z 所有城市
   $this->assign('city',$city);
   // 热门品牌
   $this->assign('re',$re);
   // 从A-M 所有汽车品牌
   $this->assign('data1',$data1);
     // 从N-Z 所有汽车品牌
   $this->assign('data2',$data2);
   // 热门车系
   $this->assign('result',$result);
    // 首页所有汽车信息 
   $this->assign('xin',$xin);
    // 瓜子精选图
    $this->assign('photo',$photo);
    // 网站配置
    $this->assign('config',$config);

    $this->display();


   }

  
     public function find()

   {


     switch('qun'){

        case '1':
          
             $order = 't.hot=1&&t.status=1';

        break;

        case '2':

              $order = 'i.uptime&&i.status=1';

        break;

        case '3':
              $order = 'i.sale&&i.status=1';
        break;

        case '4':
              $order = 'i.ontime&&i.status=1';
        break;

        case '5':
              $order = 'i.price&&i.status=1';
        break;
        case '6':
              $order = 'i.series&&i.status=1';
        break;


      }
 
    // 实例化model
    $info = M();
    // 查询车系和车辆详情信息,图片信息

    $xin = $info->field('t.typename,t.pid,t.hot,i.id,i.ontime,i.gas,i.series,i.price,i.nprice,i.comfort,i.standard,i.mile,p.cpic')->where('t.id=i.xid&&i.id=p.cid&&i.status=1')->table('__TYPE__ t,__INFO__ i,__PIC__ p')->order($order)->group('p.cid')->limit(12)->select();

         // dump($xin);exit;
      $type = M('type');
     
     
          $i=0;
     foreach ($xin as $key => $value) {
     
          // dump($value['cpic']);
          $where['id'] = $value['pid'];
          
          $xin[$i]['pai'] = $type->where($where)->select()[0]['typename'];
            
           $i++;

     }   
     // ajax 返回值
     $this->ajaxReturn($xin);

    }

   public function lists()

    {
     // 接收传值
      if(I('get.id')!=''){

          $order1 ='t.id='.I('get.id');
          $order2 ='status=1&&pid='.I('get.id');

      }else if(I('get.p')!=''){
 
          switch('p'){
            
             case '3':

              $order1 ='i.price='.['LT',5];

             break;
             case '4':

              $order1 = 'i.price='.['BETWEEN',[5,10]];

             break;
            case '5':

              $order1 = 'i.price='.['BETWEEN',[10,15]];

             break;            
            case '6':

              $order1 = 'i.price='.['BETWEEN',[15,20]];

             break;
            case '7':

              $order1 = 'i.price='.['BETWEEN',[20,30]];

             break;
            case '8':

              $order1 = 'i.price='.['BETWEEN',[30,40]];

             break;
            case '9':

              $order1 = 'i.price='.['BETWEEN',[40,60]];

             break;
            case '10':

              $order1 = 'i.price='.['GT',60];

             break;
         }



         }else if(I('get.y'!='')){

            switch('y'){

                 case '1':

                    $order1 = 'i.age ='.['LT',1];

                 break;
                 case '2':

                    $order1 = 'i.age ='.['BETWEEN',[1,3]];

                 break;
                 case '3':

                    $order1 = 'i.age ='+['BETWEEN',[3,5]];

                 break;
                 case '4':

                    $order1 = 'i.age ='.['GT',5];

                 break;

              
            }


      }else{

           $order1 ='t.hot=1';
           $order2 ='status=1&&hot=1&&pid!=0';
          

      }
      
       // dump($order1);
      //dump($order2); 
 
      // 实例化model
       $info = M();
    
     // $model =M('info');
     // 查询车系和车辆详情信息,图片信息

/*        $count = $model->count();

        // 分页个数
        $page = new \Think\Page($count,12);
        // 分页显示
        $show = $page->show();
        $xin = $model->order($order)->limit($Page->firstRow,$Page->listRows)->select();*/


   // 
    $xin = $info->
field('t.typename,t.pid,t.hot,i.tid,i.id,i.xid,i.year,i.ontime,i.uptime,i.gas,i.series,i.price,i.nprice,i.comfort,i.standard,i.mile,p.cpic,p.cid')->where('t.id=i.tid&&i.id=p.cid&&i.status=1&&'.$order1)->group('p.cid')->table('__TYPE__ t,__INFO__ i,__PIC__ p')->select();

   //  echo $info->_sql();
     
      $type = M('type');
      $conf = M('config');

     // 查询网络配置
    $config = $conf->where('status=1')->select();
     
         // dump($xin);exit;
     
          $i=0;
     foreach ($xin as $key => $value) {
     
          // dump($value['cpic']);
          $where['id'] = $value['xid'];

          $xin[$i]['xid'] = $type->where($where)->select()[0]['typename'];
            
           $i++;

     }  

        //  dump($xin);
   // 热门品牌查询
   $re = $type->where('hot=1&&pid=0&&status=1')->select();
   // 全部品牌
   $quan = $type->where('pid=0&&status=1')->select();
    // 热门车系查询
   $hot = $type->where('hot=1&&status=1')->select();
   // 选择品牌对应的车系
   $res = $type->where($order2)->select();
   $id = I('get.id');
   $data = $type->find($id);
     //  dump($data);
  // dump($res);
 
  $result = \Org\LAMP\CatTree::getTree($hot);

   //  dump($result);
   //dump($res);
   
   // 定义空数组，接收数据
   $arr = [];
   $brr= [];


  // 变量拼接汽车品牌，排序
   foreach ($quan as $ke => $value) {
    $brr[$value['letter']][] = $value;

  }

   // dump($value);

      $model =M('city');  
      // 热门城市查询
   $remen = $model->where('hot=1')->select();
   $city = $model->select();

   // 变量拼接城市，排序
   foreach ($city as $key => $value) {
    $arr[$value['letter']][] =$value;

  }

    // 变量赋值
   
     $quan = $brr;
     $city = $arr;
   // dump($page);exit;

    // dump($data1); exit;

   // 分配模板

   // 热门品牌
   $this->assign('re',$re);
   $this->assign('res',$res);
   $this->assign('remen',$remen);
   $this->assign('city',$city);
   $this->assign('data',$data);
   // 全部品牌
   $this->assign('quan',$quan);
   // 热门车系
    $this->assign('result',$result);
    // 所有汽车信息 
    $this->assign('xin',$xin);
    $this->assign('config',$config);
    // 分页操作
   // $this->assign('page',$show);

    $this->display('Index/list');
 
    }




  }